//
//  CategoryDetailCell.m
//  FieldStory
//
//  Created by itte on 2017/6/22.
//  Copyright © 2017年 funmain. All rights reserved.
//

#import "CategoryDetailCell.h"
#import "CatogoryDetailTableCell.h";

@interface CategoryDetailCell ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation CategoryDetailCell



- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"CatogoryDetailTableCell" bundle:nil] forCellReuseIdentifier:@"CatogoryDetailTableCellID"];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
    return self.subCategory.attrs.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CatogoryDetailTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CatogoryDetailTableCellID"];
    if (cell == nil) {
        cell = [[CatogoryDetailTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CatogoryDetailTableCellID"];
    }
    if (0 == indexPath.row) {
        cell.lbName.text = self.subCategory.attr_cate_name;
        cell.lbName.font = [UIFont systemFontOfSize:20];
        cell.lbName.textColor = [UIColor blackColor];
        return cell;
    }
    FSSubCategoryAtrrModel *attr = self.subCategory.attrs[indexPath.row-1];
    cell.lbName.text = [NSString stringWithFormat:@"%@:%@",attr.key_name,attr.name];
    cell.lbName.font = [UIFont systemFontOfSize:13];
    cell.lbName.textColor = [UIColor darkGrayColor];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return (0==indexPath.row)?45:20;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 200;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 1;
}


-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.width, 200)];
    headerView.backgroundColor = [UIColor whiteColor];
    UIImageView *imgHeader = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, tableView.width, 150)];
    [imgHeader sd_setImageWithURL:[NSURL URLWithString:self.subCategory.images] placeholderImage:[UIImage imageNamed:@"icon_wx"]];
    UILabel *labelName = [[UILabel alloc] initWithFrame:CGRectMake(8, 160, tableView.width-16, 30)];
    labelName.text = self.subCategory.name;
    labelName.textColor = [UIColor blackColor];
    labelName.font = [UIFont systemFontOfSize:23];
    
    [headerView addSubview:imgHeader];
    [headerView addSubview:labelName];
    
    return headerView;
}

@end
